package com.tianruan.dc.modules.sys.user.service.impl;



import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tianruan.dc.modules.sys.user.entity.dto.FeedbackDTO;
import com.tianruan.dc.modules.sys.user.entity.dto.FeedbackPageQueryDTO;
import com.tianruan.dc.modules.sys.user.entity.dto.WXFeedbackPageQueryDTO;
import com.tianruan.dc.modules.sys.user.entity.vo.FeedbackVO;
import com.tianruan.dc.modules.sys.user.mapper.FeedbackMapper;
import com.tianruan.dc.modules.sys.user.service.IFeedbackService;
import com.tianruan.dc.modules.userinfo.result.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeedbackServiceImpl implements IFeedbackService {

    @Autowired
    private FeedbackMapper feedbackMapper;

    /**
     * 增加反馈
     * @param name
     * @param phone
     * @param content
     * @param supply
     * @param create_id
     */
    @Override
    public void addFeedback(String name,String phone,String content,String supply,String create_id,String title){
        try {
            feedbackMapper.insertfeedback(name,phone,content,supply,create_id,title);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 分页查询
     * @param feedbackPageQueryDTO
     * @return
     */
    @Override
    public PageResult pageQuerry(FeedbackPageQueryDTO feedbackPageQueryDTO) {
        //开始分页查询
        PageHelper.startPage(feedbackPageQueryDTO.getPage(),feedbackPageQueryDTO.getPageSize());

        Page<FeedbackDTO> page = feedbackMapper.pageQuerry(feedbackPageQueryDTO);

        long total = page.getTotal();
        List<FeedbackDTO> records = page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public PageResult wxpageQuerry(WXFeedbackPageQueryDTO wxfeedbackPageQueryDTO) {
        //开始分页查询
        PageHelper.startPage(wxfeedbackPageQueryDTO.getPage(),wxfeedbackPageQueryDTO.getPageSize());

        Page<FeedbackDTO> page = feedbackMapper.wxpageQuerry(wxfeedbackPageQueryDTO);

        long total = page.getTotal();
        List<FeedbackDTO> records = page.getResult();
        return new PageResult(total,records);
    }


    /**
     * 更改反馈
     * @param id
     * @param name
     * @param phone
     * @param content
     * @param supply
     * @param title
     */
    @Override
    public void updateFeedback(int id,String name,String phone,String content,String supply,String title) {
        try {
            feedbackMapper.updatefeedback(id,name,phone,content,supply,title);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 删除反馈
     * @param id
     */
    @Override
    public void deleteFeedback(int id) {
        try {
            feedbackMapper.deleteFeedback(id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
